<?
class home_model extends CI_Model
{
	function __construct() 
	{
		parent::__construct();
	}
	
	function get_all($num=20,$start=0)
	{
		$this->db->where('bl_active',1) ;
		$query = $this->db->get('product', $num, $start) ;
		return $query->result() ;
	}
	
	function count_all()
	{
		$this->db->where('bl_active',1) ;
		$query = $this->db->get('product') ;
		return $query->num_rows() ;
	}
	
	public function get_id($table, $id=0, $id_name='' )
    {
        if(!empty($id)) $this->db->where($id_name, $id) ;
		$this->db->where('bl_active',1) ;
		$query = $this->db->get($table) ;
		return $query->row() ;
    }
	
	function get_name($table, $field, $id, $idname='')
	{
		$sql = "select ".$field." as name from ".$table." where ".$idname."='".$id."'" ;
		$rs = $this->db->query($sql)->row() ;
		return $rs? $rs->name : '' ;
	}
	
	function save($table, $data, $id=0, $id_name='')
    {
        if (!empty($id))
        {
            $this->db->where($id_name, $id);
            return $this->db->update($table, $data);
        }
        else
        {
            $this->db->insert($table, $data);
            return $this->db->insert_id();
        }
    }
}
?>